abstract class BaseRequest {
  String authority() {
    // https://www.wanandroid.com
    return "www.wanandroid.com";
  }

  // 路径
  String path();

  // 路径参数
  String pathParams();

  // 是否启用https
  bool useHttps = true;

  // 查询参数
  Map<String, dynamic> queryParams = Map();

  // 添加请求参数
  addParam(String key, dynamic value) {
    queryParams[key] = value;
  }

  addParams(Map<String, dynamic> map) {
    if (map != null && map.isNotEmpty) {
      for (var e in map.entries) {
        addParam(e.key, e.value);
      }
    }
  }

  // 请求头
  Map<String, dynamic> headers = Map();

  // 添加请求参数
  addheader(String key, dynamic value) {
    headers[key] = value;
  }

  addheaders(Map<String, dynamic> map) {
    if (map != null && map.isNotEmpty) {
      for (var e in map.entries) {
        addheader(e.key, e.value);
      }
    }
  }

  /// url
  String url() {
    String pathData = path();
    // 拼接path
    if (path != null) {
      String pathParamsData = pathParams();
      if (pathParamsData != null) {
        if (pathParamsData.endsWith("/")) {
          pathData = "$pathData$pathParamsData";
        } else {
          pathData = "$pathData/$pathParamsData";
        }
      }
    }
    Uri uri;
    String url = authority();
    if (useHttps) {
      uri = Uri.https(url, pathData, queryParams);
    } else {
      uri = Uri.http(url, pathData, queryParams);
    }
    return uri.toString();
  }
}
